package com.hsy.sunflowerbao.message.store

import com.flux.action.RxAction
import com.flux.action.RxStoreChange
import com.flux.dispatcher.Dispatcher
import com.hsy.sunflowerbao.base.action.ActionType
import com.hsy.sunflowerbao.base.action.Key
import com.hsy.sunflowerbao.base.store.BaseStore
import com.hsy.sunflowerbao.message.data.UserSetResult

/**
 * 我的信息数据缓存
 * Created on 2018/1/2.
 *
 * @author Yang
 */
class MyInfoStore(dispatcher: Dispatcher) : BaseStore(dispatcher) {

    /**
     * 用户信息
     */
    lateinit var setResult: UserSetResult
    /**
     * 上传头像返回结果
     */
    lateinit var avatarResult: List<String>

    override fun onRxAction(action: RxAction) {
        when (action.type) {
            ActionType.UPLOAD_IMGS -> avatarResult = action[Key.IMAGE_RESULT]
            ActionType.SET_USER_NAME -> setResult = action[Key.USER_SET]
            ActionType.SET_USER_SEX -> setResult = action[Key.USER_SET]
            else -> return
        }
        //数据变更，发出对应的Action，通知view刷新
        postChange(RxStoreChange(tag, action.type, action.success))
    }
}